#include <../network/Network.h>

#include <../client/Model.h>

#include <iostream>
#include <cassert>

using namespace std;
using namespace Network;
using namespace Client;

int main()
{
	cout << "Testowanie klasy Network::Packet: \n";

	Packet packet;

	assert(packet.size == 12);

	packet.pack();
	packet.unpack();

	packet << 3;
	packet << QString("NapisTestowy");
	packet << 0xffffffff;
	packet << QString("");
	packet << QByteArray("1234567890123");
	packet << QString("Nie");
	packet << -65535;
	packet << 0;

	packet.pack();
	packet.pack();
	packet.unpack();
	packet.pack();
	packet.unpack();
	packet.unpack();

	int res;
	QString str;
	QByteArray ba;
	packet.seek(0, 0);

	assert(packet.size == 72);

	packet >> res;
	assert(res == 3);

	packet >> str;
	assert(str == "NapisTestowy");

	packet >> res;
	assert((unsigned int)res == 0xffffffff);

	packet >> str;
	assert(str == "");

	packet >> ba;
	assert(ba == "1234567890123");

	packet >> str;
	assert(str == "Nie");

	packet >> res;
	assert(res == -65535);

	packet >> res;
	assert(res == 0);

	cout << "Done!\n";

	///////////////////

	Model model;
	SharedFileDesc * file = model.addSharedFile("testowy");

	QByteArray tmp;
	int i = 0;

	model.addJob("wynik", file->hash, file->size, file->type);

	while(1) {
		cout << i << endl;
		tmp = model.getChunk(file->hash, file->size, i);

		if (tmp.size() == 0)
			break;

		model.setChunk(file->hash, file->size, i, tmp, 1);

		i++;
	}

	return 0;
}
